package com.jhoncy.rapid.base.controller;


import com.jhoncy.rapid.base.bo.BasePermissionTypeEnum;
import com.jhoncy.rapid.base.pojo.BasePermission;
import com.jhoncy.rapid.base.pojo.BaseUser;
import com.jhoncy.rapid.base.service.BasePermissionService;
import com.jhoncy.rapid.base.service.BaseUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 为授权而开放的接口
 * @author zhuangqi
 * @date 2017/7/23.
 */
@RestController
@RequestMapping(value = "/opAuth")
public class OpenForAuthController {


    @Autowired
    private BaseUserService baseUserService;

    @Autowired
    private BasePermissionService basePermissionService;


    @GetMapping(value = "/user")
    public ResponseEntity<?> findBaseUserByUserName(@RequestParam String userName){
        BaseUser user = baseUserService.findBaseUserByUserName(userName);
        return ResponseEntity.ok(user);
    }

    @GetMapping(value = "/permissions/{userId}")
    public ResponseEntity<List<BasePermission>> findBasePermissionsByUserId(@PathVariable String userId) {
        List<BasePermission> permissions = basePermissionService.
                listByUserIdAndType(userId, BasePermissionTypeEnum.AUTH.name());
        return ResponseEntity.ok(permissions);
    }
}
